home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / CC_C / 0924.ZIP / SHELPC < prev    next >
Text File  |  1988-01-10  |  14KB  |  345 lines

  1.  
  2. /* FILE    SHELPC
  3.  
  4.                 SMC by TJMC
  5.  
  6.                (Version    2.2 created 10.1.88)
  7.                -----------------------------
  8.  
  9. General
  10. -------
  11.  
  12. SMC is a version of the    C Programming Language.    The major differences
  13. between    SMC and    the Kernighan and Ritchie C specification are:
  14.  
  15.     - The entire program is compiled as    one complete source file, which    is
  16.       compiled directly    (in one    pass) to an executable object code file;
  17.  
  18.     - Certain data types (long and double) are not implemented;
  19.  
  20.     - Arrays must be 1-dimensional only.
  21.  
  22.  
  23. Command    Line
  24. ------------
  25.  
  26.         SMC     SCEFILE  OBJFILE  -B -F -L -N -R -Dxx -Sxx \n
  27.  
  28. Options:    no Bell on error, no Float arithmetic, no compilation Listing,
  29.         function Names embedded inline, functions Report list,
  30.         set    Data size (in kbytes), set Stack size (in kbytes).
  31.  
  32. Example:    SMC    TCED EDIT.COM -fld62s1 <Return>, to compile the
  33.         editor TCED    (which has no floats), with no listing,
  34.         62k    data area and 1k stack - as it should have.
  35.  
  36.  
  37. Differences from the Kernighan
  38. and Ritchie specification:
  39. ------------------------------
  40.  
  41. 1.    SMC was    implemented, in    SMC source code, on the    Amstrad
  42.     PC1512 computer    operating under    MSDOS. It will run on any
  43.     8086/8088 computer operating MSDOS Version 3, with 256k    memory.
  44.  
  45. 2.2    The first 8 characters of an identifier    are significant.
  46.  
  47. 2.3    Keyword    'entry'    is not implemented.
  48.  
  49. 2.4    Octal digits 8 and 9, and long and double constants are    not
  50.     implemented, and will produce errors.
  51.  
  52. 2.6    Char variables are 8 bits, and int and unsigned    int are    16 bits.
  53.     Long int and short int are equivalent to int. Long float and
  54.     double are equivalent to float.    Float variables    are 48 bits,
  55.     the first 16 bit word as sign and exponent (unit value 0x200),
  56.     then a two word    mantissa, the more significant first. This
  57.     gives accuracy to 9 sig    figs, and range    1. E +/- 150.
  58.  
  59. 4.     'Register' is not acted on, except to define storage.  Local
  60.     declarations may only be made at the head of a function    body,
  61.     not at the head    of any compound    statement.
  62.  
  63. 6.1    Char variables are not sign extended on    conversion to int.
  64.  
  65. 6.2    All float arithmetic is    carried    out to single float precision.
  66.  
  67. 6.6    Conversions apply as stated, but only for char,    int, unsigned
  68.     and (single precision) float.
  69.  
  70. 7.    Expressions are    evaluated according to the stated precedence and
  71.     associativity -    but if not stated, left    to right. Arithmetic
  72.     overflow and division by 0 are both ignored.
  73.  
  74. 7.1    Function arguments are evaluated and stacked left to right.
  75.     Float arguments    are not    converted to double.
  76.  
  77. 7.2    Sizeof is permitted only on type-names,    identifier names or
  78.     structure.elements - not on expressions    generally.
  79.  
  80. 7.3    The remainder of a division has    the same sign as the dividend.
  81.  
  82. 7.5    Shifts by negative values are undefined.  Right    shifts of an int
  83.     are arithmetical, with sign extension.
  84.  
  85. 7.7    The null pointer is actually valued 0, which is    not a valid address.
  86.  
  87. 8.1    'Register' has no effect, except    to define storage. An identifier
  88.     (other than a function)    declared extern    must already be    defined.
  89.  
  90. 8.2    Long int and short int are equivalent to int. Long float and
  91.     double are taken as float.
  92.  
  93. 8.4    Multi-dimensional arrays are not implemented, nor pointers to
  94.     specified-size arrays (eg (*a)[4]). Unspecified-size arrays are
  95.     converted to pointers, except where they reserve storage - so:
  96.  
  97.         int    (*a)[];     converts to int **a;
  98.         int    a[] = {    1, 2 };     gives a 2-element array;
  99.         int    a[];  gives an error.
  100.  
  101.     However, the array subscript operator may be used multi-
  102.     dimensionally, eg. on an array of pointers to char.
  103.  
  104. 8.5    Fields are not implemented.
  105.  
  106. 8.6    Automatic variables may    not be initialised.  Within a struct, char
  107.     arrays may not be initialised by strings. Floats may be    initialised
  108.     conventionally,    or as if they were the following struct:
  109.  
  110.     struct { int exponent, MS_mantissa, LS_mantissa; }
  111.  
  112.     eg. float ten =    { 0x204, 0xA000, 0 }; (instead of 10.)
  113.  
  114. 9.2    Declarations are permitted at the head of a function body only - not
  115.     at the head of any compound statement.
  116.  
  117. 9.7    Switch statements must be compound.
  118.  
  119. 9.new    The statement inline (k1, k2, ..... kn);  compiles constant values
  120.     k1 to kn into the object code.    If any constant    is less    than 0x100
  121.     it is compiled as a single byte, else it is compiled as    a word.    All
  122.     addresses (of static variables and strings) exceed 0x100.
  123.  
  124. 10.new    Functions may be declared variadic by preceding    their definition
  125.     with type fn-dec() auto;  when the address of the first    (left hand)
  126.     argument (as pushed on the stack at run    time) will be pushed as    an
  127.     additional last    argument. The function will then see, as the value
  128.     of its first argument, the address of the top of the argument list.
  129.     Functions printf(), fprintf(), sprintf(), scanf(), fscanf() and
  130.     sscanf() are automatically compiled as variadic.
  131.  
  132. 11.    The whole program must be compiled as one source file, with all
  133.     references resolved, if    necessary using    #include files.    Static
  134.     global variables are visible throughout    the entire source program.
  135.     Extern variables must have been    defined    before declaration.
  136.  
  137. 11.1    Typedef    names are in a disjoint    class to ordinary identifiers.
  138.  
  139. 12.1    Macros may not have arguments.    #undef is not implemented.
  140.  
  141. 12.2    #include control lines may be:
  142.  
  143.         #include  filename
  144.         #include "filename"
  145.         #include <filename>    or
  146.         #include ?filename?
  147.  
  148.     where filename is a standard MSDOS file    specifier.
  149.  
  150.     In the latter case (?? delimiters) the file is taken as    a
  151.     library    file, containing only function definitions (not    data
  152.     declarations) which are    compiled only if unresolved (as    a function)
  153.     from the preceding source text.
  154.  
  155. 12.3    #if - #else - #endif control lines do not nest.
  156.  
  157. 12.4    #line is not implemented.
  158.  
  159. 12.new    #list+/#list- causes listing to    be turned on/off.
  160.  
  161. 14.3    Arrays must be declared    as 1-dimensional.
  162.  
  163. 15.    Constants must be:
  164.  
  165.         a float constant;
  166.  
  167.         a simple number, optionally    preceded by !, after #if;
  168.  
  169.         numbers or sizeof expressions, with    arithmetic operators
  170.         * %    / + - >> << & ^    | ( ), for array subscripts, or    numbers    or
  171.         character constants    with arithmetic    operators for case values;
  172.  
  173.         as case constants, or strings (taken by address) or    &variables
  174.         or &struct.elements, + or -    a constant offset (scaled as to
  175.         type), for inline or initialiser constants.
  176.  
  177. 17.    Anachronisms are not recognised.
  178.  
  179.  
  180. Low-Level Interface
  181. -------------------
  182.  
  183. SMC compiles code using    BX as the primary arithmetic register and DI as
  184. the secondary register,    as shown in Berry and Meekings 'A Book on C'.  Other
  185. registers may be used, but only    incidentally, except for floats    which use
  186. registers BX, CX and DX. Only the segment registers and    stack need be
  187. preserved on executing machine code within a SMC program. Functions return
  188. values in the BX register, or BX, CX and DX for    floats.
  189.  
  190. Note that only the inline statement inserts code into the code segment,
  191. for direct execution. To execute code in the data segment (within
  192. a literal or char array) use functions asm() or    mcrun()    in SMIO.LIB.
  193.  
  194. Memory map:
  195.  
  196.   Code segment.        Bytes 0x101/102 define the offset to the data segment.
  197.             The    SMC execution module and runtime functions are
  198.             resident from CSEG address 0x100 to    (approximately)
  199.             0x680 with floats, or 0x320    without. The program code
  200.             follows, immediately followed by the data segment.
  201.  
  202.   Data segment.        Bytes 0x100/101 point to the end of    the literals - ie.
  203.                 the start of the initialisers (and heap).
  204.             Bytes 0x102/103 point to the lowest    static data address.
  205.             Bytes 0x104/105 point to the (CSEG)    address    of main().
  206.  
  207.             The    data segment contains all areas    other than program
  208.             code: the literals start at    0x110, then the    initialisers
  209.             (overwritten by the    heap during execution) then the
  210.             static data    locations and the stack.
  211.             Any    address    (except    NULL) below 0x100 is invalid, and
  212.             may    wreck the program, as it points    to program code.
  213.  
  214.             Statics are    allocated downwards from 0x9FFC, and
  215.             top    of stack is at 0xAF40 (or in each case the
  216.             values fixed by the    command    line), though main()
  217.             arguments access just above    the top    of actual stack.
  218.             Command line words (and the    array argv) are    stored
  219.             between actual top of stack    and the    top of the declared
  220.             stack area,    normally from 0xAF60 to    0xAFF0.
  221.  
  222.             The    SMC execution module resets the    memory allocated
  223.             by MSDOS on    commencing execution, to include the program
  224.             code and all DSEG areas, ending just above the declared
  225.             stack area,    normally at DSEG offset    0xB000.
  226.  
  227.  Extra segment.        The    SMC.COM    compiler requests allocation of    0xE000
  228.             bytes of memory from MSDOS on commencement,    for
  229.             storage of intermediate code, and will halt    if this
  230.             is not available.
  231.  
  232.  
  233. Syntax Error Numbers
  234. --------------------
  235.  
  236.     10        Unbalanced function    { }'s.
  237.     12        Illegal number/constant value.
  238.     14        Illegal sizeof argument.
  239.     16        Macro definition error.
  240.     18        Undefined control line.
  241.     20        Missing/illegal storage class/type specifier.
  242.     22        Cannot store this value.
  243.     24        Expression stacks error.
  244.     26        Unrecognised type specifier/identifier.
  245.     28        Unrecognised aggregate element.
  246.     30        Expecting a    numeric    value.
  247.     32        Cannot read    element    declaration.
  248.     34        Aggregate has no elements.
  249.     36        Aggregate and tag types differ.
  250.     38        Aggregate definition syntax.
  251.     40        Illegal array specifier.
  252.     42        Expecting declarator name.
  253.     44        Expecting function argument.
  254.     46        Too    many array specifiers.
  255.     48        Illegal array size specifier.
  256.     50        Expecting a    primary.
  257.     52        Not    in the argument    list.
  258.     54        Expecting a    type specifier.
  259.     56        Expecting {    and function body.
  260.     58        Premature EOF.
  261.     60        Unbalanced loop terminator.
  262.     62        Expecting "while" after "do".
  263.     64        Expecting ":" after    "?".
  264.     66        Expecting label name.
  265.     68        No for/do/while loop pending.
  266.     70        Cannot initialise variable as pointer.
  267.     72        Cannot initialise char array here.
  268.     74        Cannot initialise this identifier.
  269.     76        Initialiser    exceeds    char width.
  270.     78        Initialiser    exceeds    declared size.
  271.     80        Cannot read    initialiser data.
  272.  
  273.  
  274. Uncorrected minor errors
  275. ------------------------
  276.  
  277. 1.  Any    expression yielding a struct or    union type at precedence level
  278.     / *    % or below will    give an    error.    Thus (*a).el will give error where
  279.     a is a struct pointer - so replace this by a->el.
  280.  
  281. 2.  Function printf in SMIO.LIB, if used to print a float with specifier
  282.     'g', left justified    and with 0 padding (right), will print blanks in
  283.     place of non-significant zeros after the decimal point.
  284.  
  285.  
  286. Examples and Compilation
  287. --------------------------
  288.  
  289. See the    source files SMC, SMINT, SMDEFS, SMIO.H    and SMIO.LIB, and the
  290. text editor TCED, for examples using (and the definitive statement of) SMC.
  291. SMC may    be recompiled by locating the five files above,    together with
  292. the object program SMC.COM, on the default drive and executing
  293. 'SMC SMC NEW.COM' as the command line.    NEW.COM    will be    an exact copy
  294. of SMC.COM after compilation.
  295.  
  296. A normal C source program (say TEST) may be compiled by    executing
  297. 'SMC TEST TEST.COM' as the command line, then may be executed immediately
  298. by 'TEST'. However note    that the SMC IO    header and library files are
  299. SMIO.H and SMIO.LIB - not STDIO.H and STDIO.LIB, though    you can    of course
  300. rename them if you wish.
  301.  
  302. During compilation (with listing on) the compiler displays a report line
  303. [aaaa/bbbb/cccc] after each function, where aaaa is the    current    CSEG
  304. hex address, bbbb is the DSEG literals address,    and cccc is the    next
  305. (descending) static data allocation address.  SMC also gives an    address
  306. report at the end of each compilation.
  307.  
  308. Note that file SMFPS.LIB contains the floating point functions,    and this
  309. file should be #included before    SMIO.LIB in any    program    using these
  310. functions, or using printf() specifiers    e, f or    g. Files SMIO.H    and SMIO.LIB
  311. contain    no floating point operators, and may be    used with command line
  312. option -F for applications using 16 bit    arithmetic only.
  313.  
  314. Functions scanf, fscanf    and sscanf are given in    file SCANF, but    are not
  315. included in file SMIO.LIB.  If you wish    to include them    in SMIO.LIB they
  316. should be taken    in as the first    functions, at the start    of the file.
  317.  
  318.  
  319. Acknowledgements and Caution
  320. ----------------------------
  321.  
  322. The author gives grateful acknowledgement to Kernighan and Ritchie, Ron    Cain
  323. and Berry and Meekings,    whose works (so    far as contributing to the concept or
  324. the source code    of SMC)    he has (he hopes correctly) assumed now    to be in the
  325. public domain. The author also wishes to acknowledge the ever continuing
  326. freshness, grace and power of the C Programming    Language.
  327.  
  328. Certain    names and works    referred to herein (MSDOS, Amstrad etc.) of course
  329. are, and will remain, proprietary.
  330.  
  331. The author hereby assigns and releases SMC into    the public domain, and
  332. hopes that users will have as much pleasure from it as him.
  333.  
  334. That said, the author can accept no responsibility or legal liability
  335. for any    loss or    damage (direct,    indirect or consequential) resulting
  336. from any defect    in or use of SMC.
  337.  
  338.  
  339. T. J. M. Caton
  340. 34, Park Road,
  341. Godalming, Surrey.
  342. 10.1.88
  343. -----------------
  344. */
  345.